﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Design.Editors;
using ProgNetDxComponents.ExtenderProviders.Options;

namespace ProgNetDxComponents.Design.Editors
{
    public class OptionCollectionEditor: NamedCollectionEditor
    {
        public OptionCollectionEditor(Type type) : base(type) { }
        protected override bool GenerateConstantClass
        {
            get
            {
                return true;
            }
        }
        protected override void ValidateCollection(object collection)
        {
            if (listbox != null)
            {
                OptionCollection coll = collection as OptionCollection;
                if (coll != null)
                {
                    List<string> list = new List<string>();
                    foreach (Option o in coll)
                    {
                        if (o.Name.IsNull())
                            AddError("At least one option does not have name");
                        else
                        {
                            if (list.Contains(o.Name))
                            {
                                AddError("Duplicated option name " + o.Name.AddDoubleQuotes());
                            }
                        }
                    }
                }
            }
        }
    }
}
